package cn.corner.flowable.learn.controller;

import org.flowable.engine.ProcessEngine;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.repository.Deployment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 流程测试控制器
 */
@RestController
@AllArgsConstructor
@Slf4j
public class FlowtestController {

    private ProcessEngine processEngine;

    /**
     * 部署流程
     * 
     * 在act_re_deployment 表可查看结果
     */
    @RequestMapping("/deploy")
    public void deployFlow() {
        // 部署流程 获取RepositoryService对象
        RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deployment = repositoryService
                .createDeployment()     
                .addClasspathResource("bpmnfile/holiday-request.bpmn20.xml") // 指定流程定义文件
                .name("请假流程")   // 流程名称
                .deploy();  // 执行部署

        log.info("流程部署成功，请查看在act_re_deployment、act_re_procdef、act_ge_bytearray表记录");
        log.info("deployment id is: {}",deployment.getId());
        log.info("deployment name is: {}",deployment.getName());
        
    }

}